package com.xfcy.blog.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.LoginDTO;
import com.xfcy.blog.service.LoginService;
import com.xfcy.blog.valid.AddGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * 后台登录控制
 * @author 晓风残月Lx
 * @date 2023/5/11 9:15
 */
@RestController
@Api(tags = "后台登录-接口")
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @PostMapping("login")
    @ApiOperation(value = "后台登陆", response = R.class, httpMethod = "POST", notes = "后台登陆")
    public R login(@Validated(AddGroup.class) @RequestBody LoginDTO loginDTO){
        return loginService.login(loginDTO);
    }

    @GetMapping("/captchaImage")
    @ApiOperation(value = "获取验证码", response = R.class, httpMethod = "GET", notes = "获取验证码")
    public R captchaImage() throws IOException {
        Map<String, String> result = loginService.captchaImage();
        return R.success("获取验证码成功", result);
    }

}
